import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ArcoResolver } from 'unplugin-vue-components/resolvers'
import { fileURLToPath, URL } from 'url'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),

        // 自动注册方法
        // https://github.com/antfu/unplugin-auto-import
        AutoImport({
            resolvers: [ArcoResolver()],
            imports: [
                'vue',
                'vitest',
                'vue-router',
                'pinia',
                // custom
                {
                    axios: [
                        // default imports
                        ['default', 'axios'] // import { default as axios } from 'axios',
                    ],
                    '@/utils/request': [
                        // default imports
                        ['default', 'request']
                    ]

                    // 自定义配置格式
                    // ,'[package-name]': [
                    //   '[import-names]',
                    //   // alias
                    //   ['[from]', '[alias]']
                    // ]
                }
            ],
            dts: 'src/types/auto-imports.d.ts'
        }),
        Components({
            // dts: true, // enabled by default if `typescript` is installed
            dirs: ['src/components', 'src/views/**/components'],
            resolvers: [ArcoResolver({ sideEffect: true })],
            // allow auto load markdown components under `./src/components/`
            extensions: ['vue', 'md'],
            // allow auto import and register components used in markdown
            include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
            dts: 'src/types/components.d.ts'
        })
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    }
})
